﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VersionComparer.Base
{
    public static class TypeExtensions
    {
        /// <summary>
        /// Returns an attribute from a given type
        /// </summary>
        /// <typeparam name="T">type of attribute</typeparam>
        /// <param name="type">type to search the attribute from</param>
        /// <param name="inherit"></param>
        /// <returns>attribute if it exists, null otherwise</returns>
        public static T GetAttribute<T>(this Type type, bool inherit = true)
            where T:Attribute
        {
            object[] attributes = type.GetCustomAttributes(typeof(T), inherit);
            if (attributes.Length == 0)
                return null;
            else
                return attributes[0] as T;
        }
    }
}
